home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / plaf / basic / BasicRadioButtonUI.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  5.8 KB  |  163 lines

  1. package javax.swing.plaf.basic;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Insets;
  10. import java.awt.Rectangle;
  11. import javax.swing.AbstractButton;
  12. import javax.swing.ButtonModel;
  13. import javax.swing.Icon;
  14. import javax.swing.JComponent;
  15. import javax.swing.SwingUtilities;
  16. import javax.swing.UIManager;
  17. import javax.swing.plaf.ComponentUI;
  18.  
  19. public class BasicRadioButtonUI extends BasicToggleButtonUI {
  20.    private static final BasicRadioButtonUI radioButtonUI = new BasicRadioButtonUI();
  21.    protected Icon icon;
  22.    private boolean defaults_initialized = false;
  23.    private static final String propertyPrefix = "RadioButton.";
  24.    private static Dimension size = new Dimension();
  25.    private static Rectangle viewRect = new Rectangle();
  26.    private static Rectangle iconRect = new Rectangle();
  27.    private static Rectangle textRect = new Rectangle();
  28.    private static Rectangle prefViewRect = new Rectangle();
  29.    private static Rectangle prefIconRect = new Rectangle();
  30.    private static Rectangle prefTextRect = new Rectangle();
  31.    private static Insets prefInsets = new Insets(0, 0, 0, 0);
  32.  
  33.    public static ComponentUI createUI(JComponent var0) {
  34.       return radioButtonUI;
  35.    }
  36.  
  37.    public Icon getDefaultIcon() {
  38.       return this.icon;
  39.    }
  40.  
  41.    public Dimension getPreferredSize(JComponent var1) {
  42.       if (((Container)var1).getComponentCount() > 0) {
  43.          return null;
  44.       } else {
  45.          AbstractButton var2 = (AbstractButton)var1;
  46.          String var3 = var2.getText();
  47.          Icon var4 = var2.getIcon();
  48.          if (var4 == null) {
  49.             var4 = this.getDefaultIcon();
  50.          }
  51.  
  52.          Font var5 = ((Component)var2).getFont();
  53.          FontMetrics var6 = ((Component)var2).getToolkit().getFontMetrics(var5);
  54.          prefViewRect.x = prefViewRect.y = 0;
  55.          prefViewRect.width = 32767;
  56.          prefViewRect.height = 32767;
  57.          prefIconRect.x = prefIconRect.y = prefIconRect.width = prefIconRect.height = 0;
  58.          prefTextRect.x = prefTextRect.y = prefTextRect.width = prefTextRect.height = 0;
  59.          SwingUtilities.layoutCompoundLabel(var1, var6, var3, var4, var2.getVerticalAlignment(), var2.getHorizontalAlignment(), var2.getVerticalTextPosition(), var2.getHorizontalTextPosition(), prefViewRect, prefIconRect, prefTextRect, var3 == null ? 0 : ((BasicButtonUI)this).getDefaultTextIconGap(var2));
  60.          int var7 = Math.min(prefIconRect.x, prefTextRect.x);
  61.          int var8 = Math.max(prefIconRect.x + prefIconRect.width, prefTextRect.x + prefTextRect.width);
  62.          int var9 = Math.min(prefIconRect.y, prefTextRect.y);
  63.          int var10 = Math.max(prefIconRect.y + prefIconRect.height, prefTextRect.y + prefTextRect.height);
  64.          int var11 = var8 - var7;
  65.          int var12 = var10 - var9;
  66.          prefInsets = ((JComponent)var2).getInsets(prefInsets);
  67.          var11 += prefInsets.left + prefInsets.right;
  68.          var12 += prefInsets.top + prefInsets.bottom;
  69.          return new Dimension(var11, var12);
  70.       }
  71.    }
  72.  
  73.    protected String getPropertyPrefix() {
  74.       return "RadioButton.";
  75.    }
  76.  
  77.    protected void installDefaults(AbstractButton var1) {
  78.       super.installDefaults(var1);
  79.       if (!this.defaults_initialized) {
  80.          this.icon = UIManager.getIcon(this.getPropertyPrefix() + "icon");
  81.          this.defaults_initialized = true;
  82.       }
  83.  
  84.    }
  85.  
  86.    public synchronized void paint(Graphics var1, JComponent var2) {
  87.       AbstractButton var3 = (AbstractButton)var2;
  88.       ButtonModel var4 = var3.getModel();
  89.       Font var5 = ((Component)var2).getFont();
  90.       var1.setFont(var5);
  91.       FontMetrics var6 = var1.getFontMetrics();
  92.       size = ((JComponent)var3).getSize(size);
  93.       viewRect.x = viewRect.y = 0;
  94.       viewRect.width = size.width;
  95.       viewRect.height = size.height;
  96.       iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
  97.       textRect.x = textRect.y = textRect.width = textRect.height = 0;
  98.       Icon var7 = var3.getIcon();
  99.       Object var8 = null;
  100.       Object var9 = null;
  101.       String var10 = SwingUtilities.layoutCompoundLabel(var2, var6, var3.getText(), var7 != null ? var7 : this.getDefaultIcon(), var3.getVerticalAlignment(), var3.getHorizontalAlignment(), var3.getVerticalTextPosition(), var3.getHorizontalTextPosition(), viewRect, iconRect, textRect, ((BasicButtonUI)this).getDefaultTextIconGap(var3));
  102.       if (var2.isOpaque()) {
  103.          var1.setColor(((Component)var3).getBackground());
  104.          var1.fillRect(0, 0, size.width, size.height);
  105.       }
  106.  
  107.       if (var7 != null) {
  108.          if (!var4.isEnabled()) {
  109.             var7 = var3.getDisabledIcon();
  110.          } else if (var4.isPressed() && var4.isArmed()) {
  111.             var7 = var3.getPressedIcon();
  112.             if (var7 == null) {
  113.                var7 = var3.getSelectedIcon();
  114.             }
  115.          } else if (var4.isSelected()) {
  116.             if (var3.isRolloverEnabled() && var4.isRollover()) {
  117.                var7 = var3.getRolloverSelectedIcon();
  118.                if (var7 == null) {
  119.                   var7 = var3.getSelectedIcon();
  120.                }
  121.             } else {
  122.                var7 = var3.getSelectedIcon();
  123.             }
  124.          } else if (var3.isRolloverEnabled() && var4.isRollover()) {
  125.             var7 = var3.getRolloverIcon();
  126.          }
  127.  
  128.          if (var7 == null) {
  129.             var7 = var3.getIcon();
  130.          }
  131.  
  132.          var7.paintIcon(var2, var1, iconRect.x, iconRect.y);
  133.       } else {
  134.          this.getDefaultIcon().paintIcon(var2, var1, iconRect.x, iconRect.y);
  135.       }
  136.  
  137.       if (var10 != null) {
  138.          if (var4.isEnabled()) {
  139.             var1.setColor(((Component)var3).getForeground());
  140.             BasicGraphicsUtils.drawString(var1, var10, var4.getMnemonic(), textRect.x, textRect.y + var6.getAscent());
  141.          } else {
  142.             var1.setColor(((Component)var3).getBackground().brighter());
  143.             BasicGraphicsUtils.drawString(var1, var10, var4.getMnemonic(), textRect.x + 1, textRect.y + var6.getAscent() + 1);
  144.             var1.setColor(((Component)var3).getBackground().darker());
  145.             BasicGraphicsUtils.drawString(var1, var10, var4.getMnemonic(), textRect.x, textRect.y + var6.getAscent());
  146.          }
  147.  
  148.          if (((JComponent)var3).hasFocus() && var3.isFocusPainted() && textRect.width > 0 && textRect.height > 0) {
  149.             this.paintFocus(var1, textRect, size);
  150.          }
  151.       }
  152.  
  153.    }
  154.  
  155.    protected void paintFocus(Graphics var1, Rectangle var2, Dimension var3) {
  156.    }
  157.  
  158.    protected void uninstallDefaults(AbstractButton var1) {
  159.       super.uninstallDefaults(var1);
  160.       this.defaults_initialized = false;
  161.    }
  162. }
  163.